# coding:utf-8
import os
from datetime import date
from io import BytesIO

import requests
from flask import Blueprint, render_template, request, redirect, url_for, flash, session, jsonify, app, make_response, \
    current_app
from sqlalchemy import or_
from werkzeug.utils import secure_filename

from App.ext import db, socketio
from App.validate_code import get_verify_code
from .models import User, Item, ShopCar, Order, Search, Provincial, Reduce, ChatMsg, History
from datetime import timedelta

# 查询商品信息
from App.ShowapiRequest import ShowapiRequest
import json

images = Blueprint('images', __name__)

@images.route('/goods', methods=['GET'])
def goods():
    return 'hello world'

@images.route('/goods/<string:filename>', methods=['GET'])
def goods_pic(filename):
    # 当前文件所在路径
    basepath = os.path.dirname(__file__)
    file_dir = os.path.join(basepath, '../static/goods/')
    if request.method == 'GET':
        if filename is None:
            pass
        else:
            image_data = open(os.path.join(file_dir, '%s' % filename), "rb").read()
            response = make_response(image_data)
            response.headers['Content-Type'] = 'image/jpg'
            return response
    else:
        pass